####!!!!!!!!!描述符必须定义在类中,不然无法实现get set delete

# 0
# 也许有个需求,当每次属性被访问时,想穿件一个日志记录,可以使用描述符实现
# get set delete至少实现一个

# 1
# get,set,delete加俩杠杠

# 2
class MyDes:
    def __get__(self, instance, owner):
        print('getting')


class Test:
    a = MyDes()
    x = a


test = Test()
test.a
test.x


# 3

class YourDesc:
    def __init__(self, value=None):
        self.val = value

    def __get__(self, instance, owner):
        return self.val - 20

    def __set__(self, instance, value):
        self.val = value + 10
        print(self.val)


class C:
    x = MyDes()


if __name__ == '__main__':  # 如果该模块执行的话,执行下边语句
    c = C()
    c.x = 10
    print(c.x)

# 10
# 10


# 4
#


# 动手吧0
print('动手吧')


class LuoDesc:
    def __init__(self, val=None, name=None):
        self.val = val
        self.name = name

    def __get__(self, instance, owner):
        print('正在获取变量 ', self.name)
        return self.val

    def __set__(self, instance, value):
        print('正在修改变量', self.name)

    def __delete__(self, instance):
        print('正在修改变量',self.name)
        print('这个变量无法删除')


class Test:
    x = LuoDesc(10, 'x')


# test = Test()
# y = test.x


def hi():
    print("hi")